function Cloud(ctx) {
  this.w = 95;
  this.h = 30;
  this.x = 0;
  this.y = 0;
  // 云朵缩放比例
  this.scale = 1; 
  this.speed = 1;
  // 云朵在画布中的位置 
  this.min_dis_x = 300;
  this.max_dis_y = 40;
  this.min_dis_y = 100;
  // 同时出现的云朵数量最多 
  this.maxNum = 5;
  this.ctx = ctx;
}

Cloud.clouds = []; // 存放所有的云朵 

 Cloud.prototype = {
   // 随机生成云朵 
   addCloud () {
     let  c = new Cloud();
     c.x = sence.width;
     c.y = randomNum(c.min_dis_y, c.max_dis_y);
     c.scale = randomNum(6, 10)/10
     c.distance = randomNum(200, 700)
     Cloud.clouds.push(c);
   },
   // 绘制云朵
   draw () {
     Cloud.clouds.forEach(v=> {
      // 164 0 95 30      1200 -52 -28.5 -9
      //  console.log(cloudSprite.x,cloudSprite.y, v.w, v.h, v.x, v.y, v.w * v.scale, v.h * v.scale);
       this.ctx.drawImage(imgSprite, cloudSprite.x,cloudSprite.y, v.w, v.h, v.x, v.y, v.w * v.scale, v.h * v.scale);
      })
      this.move();
   
   },
   // 更新云朵 
   move() {
    Cloud.clouds.forEach((v, i)=> {
      v.x = v.x - v.speed;
    
      // 判断 是否新增 
      if (Cloud.clouds.length < 5 && sence.width -Cloud.clouds[Cloud.clouds.length-1].x > Cloud.clouds[Cloud.clouds.length-1].distance ) {
        if (Math.random() > 0.95) {
          this.addCloud();
        }
      }
      // 判断 是否移除 
      if (v.x < -v.w) {
        Cloud.clouds.shift();
      }
    })
   }
 }

